package com.atguigu.rabbitmq.five;

import com.atguigu.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.Channel;

import java.util.Scanner;

/**
 * ClassName: EmitLog
 * Description: 发消息 交换机
 * Date: 2023/04/28 PM 1:48:42
 * <p>
 * project: atguigu-rabbitmq
 * package: com.atguigu.rabbitmq.five
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
public class EmitLog {

    /**
     * 交换机的名称
     */
    public static final String EXCHANGE_NAME = "logs";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, "fanout");

        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()) {
            String message = scanner.next();
            channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes());
            System.out.println("生产者发出消息：" + message);
        }
    }
}
